//
//  ColumnsCollectionReusableView.m
//  UI_14_homework_UICollectionView
//
//  Created by li cheng on 16/8/2.
//  Copyright © 2016年 li cheng. All rights reserved.
//

#import "ColumnsCollectionReusableView.h"
#import "ClassfiyCollectionViewCell.h"
#import "ColumnsOfCollectionViewCell.h"
@interface ColumnsCollectionReusableView()<UICollectionViewDelegate, UICollectionViewDataSource>
@property (nonatomic, strong) UICollectionView *classfiyCollectionView;
@property (nonatomic, strong) UILabel *label;
@property (nonatomic, strong) UIButton *moreButton;
@property (nonatomic, strong) UISearchBar *searcher;
@end
@implementation ColumnsCollectionReusableView
- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        _searcher = [[UISearchBar alloc] init];
        _searcher.backgroundColor = [UIColor redColor];
        [self addSubview:_searcher];
        _label = [[UILabel alloc] init];
        [self addSubview:_label];
        _label.text = @"栏目";
        _moreButton = [[UIButton alloc] init];
        [self addSubview:_moreButton];
        [_moreButton setTitle:@"查看更多>" forState:UIControlStateNormal];
        [_moreButton setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
        UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
        layout.itemSize = CGSizeMake(self.frame.size.width - 100, (CGRectGetHeight(frame) - 40 - 100) / 3);
        layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
        _classfiyCollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 50, self.bounds.size.width, self.bounds.size.height - 100) collectionViewLayout:layout];
        _classfiyCollectionView.backgroundColor = [UIColor whiteColor];
        [self addSubview:_classfiyCollectionView];
        _classfiyCollectionView.delegate = self;
        _classfiyCollectionView.dataSource = self;
        // 注册cell
        [_classfiyCollectionView registerClass:[ColumnsOfCollectionViewCell class] forCellWithReuseIdentifier:@"pool5"];
    }
    return self;
}
- (void)applyLayoutAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes{
    [super applyLayoutAttributes:layoutAttributes];
    _searcher.frame = CGRectMake(0, 0, self.bounds.size.width, 50);
    _label.frame = CGRectMake(0, 50, self.bounds.size.width / 3, 50);
    _moreButton.frame = CGRectMake(self.bounds.size.width / 3 *2,  50, self.bounds.size.width / 3, 50);
    _classfiyCollectionView.frame = CGRectMake(0, 100, self.bounds.size.width, self.bounds.size.height - 100);
    
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return 9;
}
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    ColumnsOfCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"pool5" forIndexPath:indexPath];
    return cell;
}
@end
